package com.yanu.t2s.controller;

import com.yanu.t2s.entity.User;
import com.yanu.t2s.entity.Yangzhi;
import com.yanu.t2s.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import net.minidev.json.JSONObject;
import com.yanu.t2s.service.YangzhiService;

import java.util.List;
//<<<<<<< HEAD

//=======

//>>>>>>> 711cb066a277f8b98d72c3c973a587e2b804358c


@CrossOrigin
@RestController
//<<<<<<< HEAD
//@RequestMapping("login")
//=======
@RequestMapping("/")
//>>>>>>> 711cb066a277f8b98d72c3c973a587e2b804358c
public class LoginController {
    @Autowired
    UserService userService;
    //登录
    @RequestMapping(value = "login",method={RequestMethod.POST, RequestMethod.GET},produces = "application/json;charset=UTF-8")
    String Login(@RequestParam String account,@RequestParam String password  ) {

        JSONObject result = new JSONObject();
        User user=userService.getUserByName(account);
        System.out.println(user.toString());
        result.put("id",user.getId());
        result.put("account", user.getAccount());
        result.put("password", user.getPassword());
        result.put("usertype", user.getUsertype());
        return result.toJSONString();
    }
    //查看个人信息
    @RequestMapping(value = "showuser",method={RequestMethod.POST, RequestMethod.GET},produces = "application/json;charset=UTF-8")
    String showuser(@RequestParam String account) {
        JSONObject result = new JSONObject();
        User user=userService.getUserByName(account);
        System.out.println(user.toString());
        result.put("id",user.getId());
        result.put("account", user.getAccount());
        result.put("password", user.getPassword());
        result.put("usertype", user.getUsertype());
        result.put("tel",user.getTel());
        result.put("name",user.getName());
        result.put("license",user.getLicense());
        result.put("faren",user.getFaren());
        result.put("address",user.getAddress());
        return result.toJSONString();
    }
    //根据用户类型查找用户
    @RequestMapping(value = "getUserByuserType",method={RequestMethod.POST, RequestMethod.GET},produces = "application/json;charset=UTF-8")
    List<User> findUsersByuserType(@RequestParam String usertype){
        if(usertype==null){
            return null;
        }else{
            return userService.findUsersByuserType(usertype);
        }
    }

    //查看所有的养殖户
    @RequestMapping(value = "showallyangzhi",method={RequestMethod.POST, RequestMethod.GET},produces = "application/json;charset=UTF-8")
    List<User> showallyangzhi() {
        List<User> userList=userService.findallyangzhi();
        return userList;
    }


}
